package com.jrx.anytxn.transaction.job.delaysms.step;

import com.jrx.anytxn.common.uitl.BeanMapping;
import com.jrx.anytxn.common.uitl.SeqUtils;
import com.jrx.anytxn.customer.entity.TlDelaySms;
import com.jrx.anytxn.number.service.ISegmentService;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.TlSmsLog;
import com.jrx.anytxn.transaction.service.ISmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class DelaySmsSendProcessor implements ItemProcessor<TlDelaySms, TlDelaySms> {
    @Autowired
    private ISegmentService segmentService;

    @Autowired
    private ISmsService iSmsService;

    Logger logger = LoggerFactory.getLogger(DelaySmsSendProcessor.class);

    @Override
    public TlDelaySms process(TlDelaySms tlDelaySms) throws Exception {
        TlSmsLog log = BeanMapping.copy(tlDelaySms, TlSmsLog.class);
        log.setProductId("");
        log.setLoanId("");
        log.setId(segmentService.getId(TransBizConstant.TL_SMS_LOG_ID));
        log.setSendStatus(tlDelaySms.getDealStatus());
        log.setChannel(tlDelaySms.getChannel());
        log.setSeqNo(TransBizConstant.DELAY_SMS_PREFIX+ SeqUtils.getSNByLength(TransBizConstant.PAYMENT_LOG_SEQ_RADOM_LENGTH));
        log.setCreateTime(null);
        log.setUpdateTime(null);
        try {
            iSmsService.smsSendProcess(log);
        } catch (Exception e) {
            logger.error("短信发送异常", e);
        }
        return tlDelaySms;
    }
}
